Fix: return 404 for invalid app_name in /run and /run_sse endpoints#5376
Fix: return 404 for invalid app_name in /run and /run_sse endpoints#5376AbhishekMauryaGEEK wants to merge 5 commits intogoogle:mainfrom
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
|
Hi maintainers, this PR fixes improper error handling for invalid app_name CLA has been signed and checks are passing. |
|
Hi @AbhishekMauryaGEEK , Thank you for your contribution! We appreciate you taking the time to submit this pull request. Please fix formatting errors by running autoformat.sh |
2c1b313 to
73a19d5
Compare
|
Hi @rohityan — just a quick follow-up on this PR. The requested changes have been applied and formatting issues are resolved. All checks are passing. Happy to make any further updates if needed. Thanks! |
Fixes #5374
Summary
Fixes improper error handling in the ADK FastAPI server where invalid
app_namevalues caused unhandled exceptions and resulted in HTTP 500responses.
This change ensures that invalid or non-existent
app_nameinputs return acontrolled
404 Not Foundresponse instead.Problem
The endpoints:
POST /runPOST /run_sseGET /apps/{app_name}/app-infocall
get_runner_async(app_name), which raises aValueErrorwhen the agentcannot be found.
This exception was not handled at the API layer, causing FastAPI to return a
500 Internal Server Error.Solution
Wrap the
get_runner_asynccall in atry/exceptblock and convertValueErrorinto a404 HTTPException.Example:
This aligns the response with expected API semantics for missing resources.
Error Handling Improvements:
try/exceptblock to handleValueErrorwhen callingget_runner_async, returning a 404 HTTP response if the specified app is not found.Logging Changes:
run_agentendpoint, simplifying the response logic.HTTP 404 Not Found { "detail": "Agent not found: 'INVALID'" }I### Impact
-- Ensures consistent and correct HTTP semantics (404 for missing resources)
-- Prevents unhandled exceptions from propagating to clients
-- Improves API stability and developer experience
Notes
-- No changes to existing successful flows
-- No additional logging or refactoring introduced
-- Change is minimal and scoped strictly to error handling
Testing
-- /run returns 404 for invalid app_name
-- /run_sse returns 404 for invalid app_name
-- /apps/{app_name}/app-info returns 404 for invalid app_name
-- /list-apps unaffected (200 OK)
-- Confirmed no regression for valid agents